// File:    TnQueryFilterBuilder.cs
// Author:  HT
// Created: Monday, November 28, 2011 9:56:55 AM
// Purpose: Definition of Class TnQueryFilterBuilder

using System;
using System.Data.SqlClient;

namespace Tayninh2011
{
   public class TnQueryFilterBuilder
   {
       String sql = String.Empty;
       SqlConnection sqlConn = null;
       String table = String.Empty;
       String dieukien = String.Empty;
       String[,] fieldName=null;
       String strFieldName = "*";
       String[,] userInfo = null;
       String connetionString = String.Empty;
       int gioihan=0;
       System.Data.CommandBehavior behavior = System.Data.CommandBehavior.SingleResult;
       public ITnQueryFilter BuildQuery()
       {
           return new TnQueryFilter(sqlConn,table,strFieldName,dieukien,behavior,gioihan);
       }

       public TnQueryFilterBuilder SqlConnection(SqlConnection sqlConnection)
       {
           this.sqlConn = sqlConnection;
           return this;
       }

       public TnQueryFilterBuilder SqlConnection(String[,] info)
       {
           return UserInfo(info);
       }

       public TnQueryFilterBuilder Table(String tableName)
       {
           this.table = tableName;
           return this;
       }

       public TnQueryFilterBuilder Fields(String fields)
       {
           this.strFieldName = fields;
           return this;
       }

       public TnQueryFilterBuilder Dieukien(String dieu_kien)
       {
           this.dieukien = dieu_kien;
           return this;
       }

       public TnQueryFilterBuilder Behavior(System.Data.CommandBehavior behaviorCommand)
       {
           this.behavior = behaviorCommand;
           return this;
       }
       public TnQueryFilterBuilder Gioihan(int gh)
       {
           this.gioihan = gh;
           return this;
       }
       public TnQueryFilterBuilder UserInfo(String[,] info)
       {
           this.userInfo = info;
           for (int j = 0; j < RootForm.UserInfo.Length / 2; j++)
           {
               connetionString += this.userInfo[j, 0] + "=" + this.userInfo[j, 1];
               connetionString += ";";
           }
           this.sqlConn = new SqlConnection(connetionString);
           return this;
       }
   }
}
